package com.daidai

import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.DialogFragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.daidai.activitys.*
import com.daidai.base.BaseActivity
import com.daidai.tools.G
import com.daidai.spinner.R

class DemoViewHolder(val rootView: View,
                     val tvText:TextView
):RecyclerView.ViewHolder(rootView)
class DemoAdapter(val demoActivity:DemoListActivity): RecyclerView.Adapter<DemoViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DemoViewHolder {
        val rootView = LayoutInflater.from(parent.context).inflate(R.layout.item_demo_list,parent,false)
        return DemoViewHolder(rootView,
            rootView.findViewById(R.id.tvText)
        )
    }

    override fun onBindViewHolder(holder: DemoViewHolder, position: Int) {
        val pair = DemoListActivity.dataLst[position]
        holder.tvText.text = pair.first
        holder.rootView.setOnClickListener {
            G.elog("clicked: ${pair.first}")
            demoActivity.startActivity(Intent(demoActivity,pair.second))
        }
    }

    override fun getItemCount(): Int {
        return DemoListActivity.dataLst.size
    }
}

class DemoListActivity : BaseActivity() {

    companion object{
        val dataLst = ArrayList<Pair<String,Class<*>>>()
        init {
            dataLst += "试试DialogFragment" to DialogFragmentActivity::class.java
            dataLst += "试试Window" to WindowActivity::class.java
            dataLst += "试试 LightService" to LightServiceActivity::class.java
            // dataLst += "FlingActivity" to FlingActivity::class.java
            dataLst += "自定义滚动的View"  to RollViewActivity::class.java
            dataLst += "TestTween" to TestTween::class.java
            dataLst += "微信登陆" to WXLoginActivity::class.java
            dataLst += "查看包名" to ViewPackageActivity::class.java
            dataLst += "XPermission库测试"  to XpermisstionActivity::class.java
            dataLst += "Bitmap测试" to BitmapActivity::class.java
            dataLst += "混合" to XperformActivity::class.java
            dataLst += "测试帧动画" to FrameAnimationActivity::class.java
            dataLst += "测试View的位置" to ViewPosActivity::class.java
            dataLst += "RemoteView" to RemoteViewActivity::class.java
            dataLst += "Spinner" to SpinnerActivity::class.java
            dataLst += "协程获取数据" to CoroActivity::class.java
            dataLst += "测试Window" to TestWindowActivity::class.java
            dataLst += "PopupWindow监听返回键" to TestPopWindowActivity::class.java
            dataLst += "Test Style" to TestStyleActivity::class.java
            dataLst += "浏览器" to BrowserActivity::class.java
            dataLst += "LineChart" to LineChartActivity::class.java
            dataLst += "Surfview" to SurfaceActivity::class.java
        }
    }

    lateinit var rvLst:RecyclerView
    override fun getContentViewResId() = R.layout.demo_list

    override fun initView() {
        rvLst = findViewById(R.id.rvLst)

        val layoutMgr = LinearLayoutManager(this)
        layoutMgr.orientation = LinearLayoutManager.VERTICAL
        rvLst.layoutManager = layoutMgr

        rvLst.adapter = DemoAdapter(this)
    }

    override fun initData() {
    }


    override fun isUseFullScreenMode(): Boolean = false

}